/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.Main;
import control.StatestikHandler;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author Morten J, Morten B & Jonas
 */
public class Statistik extends javax.swing.JPanel {

    private TableRowSorter sorter;
    private DefaultTableModel model;
    private StatestikHandler sh;

    /**
     * Creates new form Statistik
     */
    public Statistik() {
        initComponents();

        model = (DefaultTableModel) jStatistikTable.getModel();
        sorter = new TableRowSorter<>(model);
        jStatistikTable.setRowSorter(sorter);
        sh = new StatestikHandler(model);
    }

    public JLabel getLabel() {
        return jStatestikFeedback;
    }

    public void clearFeedback() {
        jStatestikFeedback.setText("");
    }

    public void getStatestik() {
        if (!jTextSearch.getText().isEmpty()) {
            if (jTextSearch.getText().length() == 10 && jTextSearch.getText().substring(2, 3).equals("-") && jTextSearch.getText().substring(5, 6).equals("-")) {
                sh.createStatestik(jTextSearch.getText());
            } else {
                GUI.getGuiHandler().setFeedbackMessage("Du har indtastet et forkert datoformat. Eksempel: 01-05-2012", Main.getRED_COLOR());
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanSearch = new javax.swing.JPanel();
        jBtnSearch = new javax.swing.JButton();
        jTextSearch = new javax.swing.JTextField();
        jPanStatistik = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jStatistikTable = new javax.swing.JTable();
        jStatestikFeedback = new javax.swing.JLabel();

        setBackground(new java.awt.Color(186, 153, 108));

        jPanSearch.setBackground(new java.awt.Color(186, 153, 108));
        jPanSearch.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240)), "Søg dato (dd-mm-yyyy)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 0, 11), java.awt.Color.darkGray)); // NOI18N

        jBtnSearch.setBackground(new java.awt.Color(218, 191, 137));
        jBtnSearch.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jBtnSearch.setForeground(new java.awt.Color(25, 25, 25));
        jBtnSearch.setText("Søg");
        jBtnSearch.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jBtnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSearchActionPerformed(evt);
            }
        });

        jTextSearch.setBackground(new java.awt.Color(240, 240, 240));
        jTextSearch.setFont(new java.awt.Font("Verdana", 0, 18)); // NOI18N
        jTextSearch.setForeground(new java.awt.Color(25, 25, 25));
        jTextSearch.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(250, 250, 250)));
        jTextSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextSearchActionPerformed(evt);
            }
        });
        jTextSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextSearchKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanSearchLayout = new javax.swing.GroupLayout(jPanSearch);
        jPanSearch.setLayout(jPanSearchLayout);
        jPanSearchLayout.setHorizontalGroup(
            jPanSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 470, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBtnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanSearchLayout.setVerticalGroup(
            jPanSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanSearchLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBtnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(jTextSearch))
                .addContainerGap())
        );

        jPanStatistik.setBackground(new java.awt.Color(186, 153, 108));
        jPanStatistik.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240)), "Besøgende", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 0, 11), java.awt.Color.darkGray)); // NOI18N
        jPanStatistik.setForeground(new java.awt.Color(25, 25, 25));

        jStatistikTable.setBackground(new java.awt.Color(206, 173, 128));
        jStatistikTable.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        jStatistikTable.setForeground(new java.awt.Color(25, 25, 25));
        jStatistikTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Voksen",  new Integer(0)},
                {"Barn",  new Integer(0)},
                {"Gratist",  new Integer(0)}
            },
            new String [] {
                "Billet", "Antal"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jStatistikTable.setGridColor(new java.awt.Color(250, 250, 250));
        jScrollPane1.setViewportView(jStatistikTable);

        javax.swing.GroupLayout jPanStatistikLayout = new javax.swing.GroupLayout(jPanStatistik);
        jPanStatistik.setLayout(jPanStatistikLayout);
        jPanStatistikLayout.setHorizontalGroup(
            jPanStatistikLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanStatistikLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jScrollPane1)
                .addGap(10, 10, 10))
        );
        jPanStatistikLayout.setVerticalGroup(
            jPanStatistikLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanStatistikLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jStatestikFeedback.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        jStatestikFeedback.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanStatistik, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jStatestikFeedback, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jPanSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jStatestikFeedback, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jPanStatistik, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSearchActionPerformed
        getStatestik();
    }//GEN-LAST:event_jBtnSearchActionPerformed

    private void jTextSearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextSearchKeyReleased
        jTextSearch.setText(jTextSearch.getText().replaceAll("[^\\d-]", ""));
    }//GEN-LAST:event_jTextSearchKeyReleased

    private void jTextSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextSearchActionPerformed
        getStatestik();
    }//GEN-LAST:event_jTextSearchActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnSearch;
    private javax.swing.JPanel jPanSearch;
    private javax.swing.JPanel jPanStatistik;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jStatestikFeedback;
    private javax.swing.JTable jStatistikTable;
    private javax.swing.JTextField jTextSearch;
    // End of variables declaration//GEN-END:variables

}
